package juc.imooccache;

import juc.imooccache.computable.MayFail;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author fangbin
 * @desc
 * @date 2020/7/6 7:07
 */
public class ThreadPoolTest {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(100);
        ImoocCache10<String,Integer> imoocCache10 = new ImoocCache10<>(new MayFail());
        long start = System.currentTimeMillis();
        for(int i=0;i<100;i++){
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    Integer result = null;
                    try {
                        result = imoocCache10.compute("666",5);
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("result:"+result);
                }
            });
        }
        executorService.shutdown();
        while (!executorService.isTerminated()){
           // System.out.println("......");
        }
        long currentTime = System.currentTimeMillis();
        System.out.println("总耗时："+(currentTime-start)+"ms");
    }
}
